<template>
  <div>
    <label><input :value="value.name" @input="onInput" @keydown.enter="addCourse" ref="input">增加课程</label>
    <button @click="$bus.$emit('close-alert')">清除所有弹框</button>
  </div>
</template>

<script>

import Vue from 'vue'

// 如果$bus不在这里定义，则需要传进来。模板中不能直接访问
Vue.prototype.$bus = new Vue()
export default {
  name: "courseAdd",
  props: {
    value: {
      dataType: String,
      default: ''
    },
  },
  mounted() {
    this.$refs.input.focus()
  },
  methods: {
    onInput(e) {
      this.$emit('input', {name: e.target.value})
      console.log(e.target.value, '-', this.value)
    },
    addCourse() {
      this.$emit('add-course')
    }
  },

}
</script>

<style scoped>

</style>